<?php

namespace SinoPHP\BbdBoss\Api;

/**
 * 自建ip信息同步接口
 *
 * Params:
 *      data:startTime    (int)     查询起始时间
 *      data:endTime      (int)     查询结束时间
 */
class BuildServerIp extends ApiAbstract {

    public function v_1_0_0() {
        $params = $this->requestParams;

        $where['belong_type'] = 0;
        if (isset($params['startTime']) && isset($params['endTime'])) {
            $where = ['update_time|<>' => [$params['startTime'], $params['endTime']]];
        }

        $fields = 'ip_id, ip, hostname, server_area_id, server_area, status, update_time, is_delete as del, isp, physical_node, physical_node_id, device_number_id, large_area, country, province, city, province_abbreviate, city_abbreviate';
        $ipData = model('ServerIp')->getList($fields, $where);
        foreach ($ipData as &$value) {
            $value['is_delete'] = 1;
            $value['ip_id'] = intval($value['ip_id']);
            if ($value['status'] == 1 && $value['del'] == 0) {
                $value['is_delete'] = 0;
            }
            unset($value['status']);
            unset($value['del']);
        }
        $this->success($ipData);
    }

}